#pragma once

#include <unordered_map>
#include <assert.h>
#include "EntityBase.h"

namespace walker_sm
{
	class EntityManager
	{
	public:
		static EntityManager* GetInstance()
		{
			static EntityManager instance;
			return &instance;
		}

		void RegisterEntity(EntityBase* entity)
		{
			entityMap.insert(std::make_pair(entity->GetId(), entity));
		}

		EntityBase* GetEntityById(int id)
		{
			auto it = entityMap.find(id);
			assert(it != entityMap.end());
			return it->second;
		}

		void RemoveEntity(EntityBase* entity)
		{
			auto it = entityMap.find(entity->GetId());
			assert(it != entityMap.end());
			entityMap.erase(it);
		}

		EntityBase* RemoveEntity(int id)
		{
			auto it = entityMap.find(id);
			assert(it != entityMap.end());
			return entityMap.erase(it)->second;
		}


	private:
		EntityManager() { }
		EntityManager(const EntityManager&) { }
		EntityManager& operator=(const EntityManager&) { }

	private:
		std::unordered_map<int, EntityBase*> entityMap;
	};
}

